//
//  HZY_BaseViewController.m
//  LaomiKit
//
//  Created by laomi on 2020/8/4.
//  Copyright © 2020 laomi. All rights reserved.
//

#import "HZY_BaseViewController.h"
#import "MJRefresh.h"
#import "NSString+language.h"
const int default_page_start = 0;
@interface HZY_BaseViewController ()

@end

@implementation HZY_BaseViewController

@synthesize callback;

- (void)viewDidLoad {
    [super viewDidLoad];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textChanged:) name:UITextFieldTextDidChangeNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(laomi_textChange:) name:UITextFieldTextDidChangeNotification object:nil];
    // Do any additional setup after loading the view.
}
-(void)textChanged:(NSNotification*)note
{
    
}
-(void)laomi_textChange:(NSNotification *)note
{
    
}
/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */
-(void)dealloc{
    [[NSNotificationCenter defaultCenter]removeObserver:self];
    NSLog(@"%@ release",self);
}


+(void)laomi_flushTableOrCollectionData:(UIScrollView<LAOMIEmptyErrorViewProtocal> *)table dataSource:(NSArray *)datasource isMore:(BOOL)isMore isError:(BOOL)isError errorCallBack:(LAOMITableCollectionCallback)errorCallback refreshCallBack:(LAOMITableCollectionCallback)reflushCallBack pulldownCallBack:(LAOMITableCollectionCallback)pulldownCallBack
{
    LAOMIAsyncRunInMain({
        if (isError) {
            [table showErrorView];
        }
        if(datasource.count==0){
            [table showEmptyView];
        }
        if (reflushCallBack&&table.mj_header==nil) {
            MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
                [table.mj_footer endRefreshing];
                reflushCallBack();
            }];
   
            header.lastUpdatedTimeLabel.hidden = YES;
            [header setTitle:[@"common.pulldown.refresh.title" stringForLanguage:[NSString laomi_languageIdentifier]] forState:MJRefreshStateIdle];
           [header setTitle:[@"common.pulldown.refresh.title" stringForLanguage:[NSString laomi_languageIdentifier]] forState:MJRefreshStatePulling];
           [header setTitle:[@"common.pulldown.refresh.title" stringForLanguage:[NSString laomi_languageIdentifier]] forState:MJRefreshStateRefreshing];
           [header setTitle:[@"common.pulldown.refresh.title" stringForLanguage:[NSString laomi_languageIdentifier]] forState:MJRefreshStateWillRefresh];
           [header setTitle:[@"common.no.more.title" stringForLanguage:[NSString laomi_languageIdentifier]] forState:MJRefreshStateNoMoreData];
            table.mj_header = header;
        }
        [table.mj_header endRefreshing];
        
        if (table.mj_footer==nil) {
            MJRefreshBackNormalFooter *footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
                [table.mj_header endRefreshing];
                if (isMore&&pulldownCallBack) {
                    pulldownCallBack();
                }
            }];
            [footer setTitle:[@"common.pullup.loadmore.title" stringForLanguage:[NSString laomi_languageIdentifier]] forState:MJRefreshStateIdle];
            [footer setTitle:[@"common.pullup.loadmore.title" stringForLanguage:[NSString laomi_languageIdentifier]] forState:MJRefreshStatePulling];
            [footer setTitle:[@"common.pullup.loadmore.title" stringForLanguage:[NSString laomi_languageIdentifier]] forState:MJRefreshStateRefreshing];
            [footer setTitle:[@"common.pullup.loadmore.title" stringForLanguage:[NSString laomi_languageIdentifier]]  forState:MJRefreshStateWillRefresh];
            [footer setTitle:[@"common.no.more.title" stringForLanguage:[NSString laomi_languageIdentifier]]  forState:MJRefreshStateNoMoreData];
            table.mj_footer = footer;
        }
        if(isMore==NO)//没有更多数据;//结束方式
        {
            [table.mj_footer endRefreshingWithNoMoreData];
        }else{
            [table.mj_footer endRefreshing];
        }
        [table reloadData];
    })
   
    
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
